// FFEncodeFilter.h : main header file for the FFEncodeFilter DLL
//

#pragma once

#ifndef __AFXWIN_H__
	#error "include 'stdafx.h' before including this file for PCH"
#endif

#include "resource.h"		// main symbols
#include "FFEncondeInputPin.h"
#include "ffFileSink.h"
#include "MyPosPassThru.h"
#include "MediaFrame.h"
#include "MediaBuffer.h"


#define MY_FILTER_NAME _T(".AAA FFENCODE FILTER")

class CFFEncodeFilter 
	:	public CBaseFilter
	,	public CCritSec
	,	public CAMThread
	,	public IAMFilterMiscFlags		
	,   public CFfFileSink
	,	public CProfileManager
{
public:
	CFFEncodeFilter(LPUNKNOWN lpunk, HRESULT* phr);
	virtual ~CFFEncodeFilter();
	DECLARE_IUNKNOWN
	STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);

	//CBaseFilter
	virtual int GetPinCount();
	virtual CBasePin* GetPin(int n);	

	STDMETHODIMP Stop();
	STDMETHODIMP Pause();
	STDMETHODIMP Run(REFERENCE_TIME tStart);
	
	//IAMFilterMiscFlags
	ULONG STDMETHODCALLTYPE GetMiscFlags(void);
	
	//helper
	bool addActivePins();
	COptionParameter* getSetting();
	void PutSetting(COptionParameter* pSetting);
	CMediaProp* GetMediaProp(){return &m_srcMediaProp;};

private:
	//CAMThread
	enum{CMD_EXIT, CMD_RUN, CMD_PAUSE};
	DWORD ThreadProc();	
	void  NotifyComplete();
	void  NotifyError(void* pError);
	void  QueryActiveMediaBuffer();
	bool  GetFirstFrame(CMediaFrame** pFrame, CMediaBuffer** pBuffer);
	void  RemoveActiveMediaBuffer(CMediaBuffer* pBuffer);
	

private:
	CFFEncodeInputPin* m_pInputAudioPin;
	CFFEncodeInputPin* m_pInputVideoPin;
	CFfFileSink filssink;
	CMyPosPassThru* m_pSeekThrough;
	CCritSec   m_ObjectCreationLock;

	COptionParameter*   m_pSetting;
	std::deque<CMediaBuffer*> m_qAvtiveBuffer;
	CMediaProp m_srcMediaProp;
	
};
